<?php
/**
 * Created by PhpStorm.
 * User: 王文凡<787802868@qq.com>
 * Date: 2016/8/15 0015
 * Time: 09:47
 */

namespace Common\Model;


use Think\Model;

class TailafterModel extends Model
{
    protected $_validate = [
        ['pr_id', 'require', '请选择订单工序！'],
        ['title', 'require', '标题必须填写！'],
        ['content', 'require', '内容必须填写！']
    ];
   //新增或更新订单状态
    public function orderState($tid=''){
        if(empty($tid)){
            if($this->create()==false){
                $arr['state']='error';
                $arr['info']=$this->getError();
                return $arr;
            }else{
                if($this->add()){
                    $pr_id=I('post.pr_id');
                    M('Process')->where("pr_id=%d",$pr_id)->save(['completeTime'=>time()]);
                    $arr['state']='success';
                    $arr['info']='更新状态成功';
                }else{
                    $arr['state']='error';
                    $arr['info']='更新状态失败';
                }
                return $arr;
            }
        }else{
            if($this->where("tid=%d",$tid)->save($_POST)){
                $arr['state']='success';
                $arr['info']='修改状态成功';
            }else{
                $arr['state']='error';
                $arr['info']='修改状态失败';
            }
            return $arr;
        }
    }
    //查询订单状态信息
    public function stateList($rid){

        return $this->where("rid=%d and status=%d",[$rid,1])->select();
    }
}


















